from django.db import models

# Create your models here.

class Students(models.Model):
    object = models.Manager()
    name = models.CharField(max_length=30)
#    pwd = models.CharField(max_length=30)
    sex = models.CharField(max_length=30)
    cls = models.ForeignKey('Classes', on_delete=models.CASCADE)

class Classes(models.Model):
    object = models.Manager()
    caption = models.CharField(max_length=30, unique=True)
#    cls = models.IntegerField(max_length=2)


    # def cls_del(self, cls):
    #     """
    #     删除班级
    #     :param cls:
    #     :return:
    #     """
    #     message = True
    #     try:
    #         self.Classes.object.remove({"cls": cls})
    #     except Exception as e:
    #         message = False
    #     else:
    #         return message
    #
    # @staticmethod
    # def cls_info(self):
    #     """
    #     获取班级信息
    #     :param self:
    #     :return:
    #     """
    #     cls_list = self.Classes.object.all()
    #     return cls_list



#class Subject(models.Model):
#    '''
#    科目
#    '''
#    name = models.CharField(max_length=30)

class Teachers(models.Model):
    object = models.Manager()
    name = models.CharField(max_length=30)
#    pwd = models.CharField(max_length=30)

class TeacherClass(models.Model):
    object = models.Manager()
    teacher = models.ForeignKey('Teachers', on_delete=models.CASCADE)
    cls = models.ForeignKey('Classes', on_delete=models.CASCADE)

    class Meta:
        # 建立联合唯一索引
        unique_together = [
            ('teacher', 'cls')
        ]


class Administrator(models.Model):
    object = models.Manager()
    name = models.CharField(max_length=32)
    pwd = models.CharField(max_length=32)

#测试联表操作实验
class Boy(models.Model):
    name = models.CharField(max_length=32)


class Girl(models.Model):
    name = models.CharField(max_length=32)


class Love(models.Model):
    b = models.ForeignKey('Boy', on_delete=models.CASCADE)
    g = models.ForeignKey('Girl', on_delete=models.CASCADE)

    # 创建联合唯一索引
    # class Meta:
    #   unique_together = [
    #     ('b','g')，
    #   ]
